<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "business_pig_price_detail".
 *
 * @property string $id
 * @property integer $pigpriceid
 * @property integer $pigid
 * @property string $type
 * @property string $price
 * @property string $otherdesc
 * @property integer $createtime
 * @property string $unit
 * @property string $weight
 * @property integer $status
 */
class BusinessPigPriceDetail extends \yii\db\ActiveRecord
{



    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '库存',      //用于修改了什么的显示
        'mainfield' => 'id',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];



    const STATUS_SELL = 1;
    const STATUS_DEFAULT = 0;
    public static $statues = [
        self::STATUS_DEFAULT => '未售卖',
        self::STATUS_SELL => '已售卖'
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'business_pig_price_detail';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['pigpriceid', 'pigid', 'createtime', 'status'], 'integer'],
            [['price', 'weight'], 'number'],
            [['type'], 'string', 'max' => 20],
            [['otherdesc'], 'string', 'max' => 255],
            [['unit'], 'string', 'max' => 10],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pigpriceid' => '猪肉分割id',
            'pigid' => '仔猪id',
            'type' => '分割类型',
            'price' => '价格',
            'otherdesc' => '其他情况备注',
            'createtime' => '入库时间',
            'unit' => '销售单位',
            'weight' => '重量(kg)',
            'status' => '库存状态',
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取对应的分割的仔猪
     */
    public function getPig()
    {
        return $this->hasOne(BusinessPig::className(),['id'=>'pigid']);
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取对应的分割单据
     */
    public function getPigprice()
    {
        return $this->hasOne(BusinessPigPrice::className(),['id'=>'pigpriceid']);
    }



}
